package cn.edu.scau.cmi.chenmiaopeng;

import java.io.IOException;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.TextArea;
import javafx.scene.control.Toggle;
import javafx.stage.Stage;

import cn.edu.scau.cmi.chenmiaopeng.controller.adapter.*;

public class AdapterClient extends Application{
	private RadioButton classAdapter;
	private RadioButton objectAdapter;
	private TextArea textarea;
	private final ToggleGroup adapterGroup = new ToggleGroup(); 
	
	public static void main(String[] args) {
		launch(args);
	}
	public void start(Stage primaryStage) throws Exception{
		try {
		  FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/chenmiaopeng/ui/adapter/AdapterUI.fxml"));
		  Parent root = loader.load();
		   
		  classAdapter = (RadioButton)loader.getNamespace().get("classAdapter");
		  objectAdapter = (RadioButton)loader.getNamespace().get("objectAdapter");
		  textarea = (TextArea)loader.getNamespace().get("textarea");
		  initView(loader);
		  
		  Scene scene = new Scene(root, 414, 462);
		  primaryStage.setScene(scene);
		  primaryStage.setTitle("适配器模式");
		  
		  AdapterController adapterController = new AdapterController();
		  adapterController.setTextArea(textarea);
		  adapterController.showStudentInfo();  //从外部调用
		  primaryStage.show();
		}
		catch(IOException e) {
			e.printStackTrace();
		}
     }
	private void initView(FXMLLoader loader) {
		classAdapter.setToggleGroup(adapterGroup);
		objectAdapter.setToggleGroup(adapterGroup);
		classAdapter.setSelected(true);
		AdapterController con = loader.getController();
		con.addToggleListener(adapterGroup);
	}
}
//(RadioButton)root.lookup("#objectAdapter");